package Com.javaserver.servlet;

import Com.javaserver.bean.rewland;
import Com.javaserver.dao.rewlandserver;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/rewlandadd")
public class rewanlandaddserverlet extends HttpServlet {
    rewlandserver rewd=new rewlandserver();

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setCharacterEncoding("UTF-8");
        req.setCharacterEncoding("UTF-8");
        String theme=req.getParameter("theme");//奖惩主题
        String type=req.getParameter("type");//奖惩类型
        if (type.equals("1")) {
            type="奖励";
        }else {
            type="惩罚";
        }
        String money=req.getParameter("money");//奖惩金额
        String time=req.getParameter("time");//奖惩时间
        String reason=req.getParameter("reason");//奖惩原因
        rewland rew=new rewland();
        rew.setP_theme(theme);
        rew.setP_type(type);
        rew.setP_money(money);
        rew.setP_time(time);
        rew.setP_reason(reason);
        if (rewd.rewlandadd(rew)==null){
            req.getSession().setAttribute("msg","添加失败");
            resp.sendRedirect(req.getContextPath()+"/AddRewland.jsp");
        }else {
            //这个地方放重新刷新的页面List
            List<rewland> list=rewd.rewlist(1);
            req.getSession().setAttribute("rewlist",list);
            req.getSession().setAttribute("msg","添加成功");
            resp.sendRedirect(req.getContextPath()+"/rewland.jsp");
        }
    }
}
